<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增配置')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-config-add">
		     <input id="title" name="title" class="form-control" type="hidden">
		    <div class="form-group">    
                <label class="col-sm-3 control-label">连续天数：</label>
                <div class="col-sm-8">
                    <input name="dayNum" class="form-control" type="number" required>
                </div>
            </div>
		    <div class="form-group">    
                <label class="col-sm-3 control-label">奖励积分：</label>
                <div class="col-sm-3">
                    <div class="radio-box" th:each="dict : ${@dict.getType('shop_yes_no')}">
						<input type="radio" th:id="${dict.dictCode}" name="isPoint" th:value="${dict.dictValue}" th:checked="${dict.default}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
                </div>
                
                 <label class="col-sm-2 control-label">奖励数量：</label>
                <div class="col-sm-3">
                    <input id="point" name="point" class="form-control" type="number" value="1" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">奖励成长值：</label>
                <div class="col-sm-3">
                    <div class="radio-box" th:each="dict : ${@dict.getType('shop_yes_no')}">
						<input type="radio" name="isGrowth" th:value="${dict.dictValue}" th:checked="${dict.dictValue=='1'?true:false}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
                </div>
                
                 <label class="col-sm-2 control-label">奖励数量：</label>
                <div class="col-sm-3">
                    <input id="growth" name="growth" class="form-control" type="number" value="0" required>
                </div>
            </div>
            
            <div class="form-group">    
                <label class="col-sm-3 control-label">显示排序：</label>
                <div class="col-sm-8">
                    <input name="sort" class="form-control" type="number" required>
                </div>
            </div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "shop/member/sign";
		
		$("#form-config-add").validate({
			onkeyup: false,
			rules:{
				dayNum:{
					remote: {
		                url: prefix + "/checkDayNumUnique",
		                type: "post",
		                dataType: "json",
		                data: {
							"dayNum": function() {
					    		return $("input[name='dayNum']").val();
					        }
		                }
		            }
				},
			},
			messages: {
		        "dayNum": {
		            remote: "配置天数已存在"
		        }
		    },
		    focusCleanup: true
		});
		

		function submitHandler() {
			if ($.validate.form()) {
				var title="";  
				if($('input:radio[name="isPoint"]:checked').val()==0){
					title+="奖励"+$("#point").val()+"积分;"
				}else{
					$("#point").val(0);
				}
				if($('input:radio[name="isGrowth"]:checked').val()==0){
					title+="奖励"+$("#growth").val()+"成长值;"
				}else{
					$("#growth").val(0);
				}
				$("#title").val(title);
				$.operate.save(prefix + "/add", $('#form-config-add').serialize());
			}
		}
	</script>
</body>
</html>
